<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>倒计时</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #con {
            width: 200px;
            height: auto;
            margin: 50px auto;
        }

        #one,
        #two,
        #three {
            float: left;
            width: 50px;
            height: 50px;
            line-height: 50px;
            text-align: center;
            margin-right: 10px;
            background-color: aqua;
            color: #000;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <div id="con">
        <!-- <h2>现在距离干饭</h2> -->
        <div id="one">00</div>
        <div id="two">00</div>
        <div id="three">00</div>
    </div>
    <script>
        //输入对话框，设置秒杀结束时间
        var end = new Date(prompt('秒杀结束时间：', '2022/11/11 17:00:00'));
        //显示剩余时间
        function showTime() {
            //得到现在时间
            var now = new Date();
            //计算剩余时间，单位是毫秒数
            var total = end - now;
            //计算剩余小时数,分钟数，秒数
            var hours = parseInt(total / (60 * 60 * 1000));
            var mins = parseInt((total - hours * 60 * 60 * 1000) / (60 * 1000));
            var ss = parseInt((total - hours * 60 * 60 * 1000 - mins * 60 * 1000) / 1000);
            //将时间显示到对应div中
            document.querySelector('#one').innerHTML = hours < 10 ? '0' + hours : hours;
            document.querySelector('#two').innerHTML = mins < 10 ? '0' + mins : mins;
            document.querySelector('#three').innerHTML = ss < 10 ? '0' + ss : ss;
        }
        //初始化
        showTime();
        //循环计数
        setInterval(showTime, 1000);
    </script>
</body>

</html>